from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-07 14:11:40.002912
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 07, Aug, 2021
Time: 14:11:45
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5670
Nobs: 376.000 HQIC: -46.1342
Log likelihood: 4031.74 FPE: 6.33962e-21
AIC: -46.5076 Det(Omega_mle): 5.00574e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.492063 0.096857 5.080 0.000
L1.Burgenland 0.104809 0.049931 2.099 0.036
L1.Kärnten -0.116953 0.023990 -4.875 0.000
L1.Niederösterreich 0.161819 0.106290 1.522 0.128
L1.Oberösterreich 0.089423 0.105022 0.851 0.395
L1.Salzburg 0.293269 0.051145 5.734 0.000
L1.Steiermark 0.011292 0.067758 0.167 0.868
L1.Tirol 0.138950 0.053770 2.584 0.010
L1.Vorarlberg -0.108925 0.048186 -2.261 0.024
L1.Wien -0.060411 0.093874 -0.644 0.520
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.024844 0.233972 -0.106 0.915
L1.Burgenland -0.032500 0.120616 -0.269 0.788
L1.Kärnten 0.035973 0.057952 0.621 0.535
L1.Niederösterreich -0.221579 0.256759 -0.863 0.388
L1.Oberösterreich 0.556399 0.253696 2.193 0.028
L1.Salzburg 0.308534 0.123548 2.497 0.013
L1.Steiermark 0.108509 0.163679 0.663 0.507
L1.Tirol 0.308102 0.129890 2.372 0.018
L1.Vorarlberg -0.019660 0.116400 -0.169 0.866
L1.Wien -0.005759 0.226767 -0.025 0.980
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.263672 0.050180 5.255 0.000
L1.Burgenland 0.096073 0.025869 3.714 0.000
L1.Kärnten -0.005437 0.012429 -0.437 0.662
L1.Niederösterreich 0.224663 0.055067 4.080 0.000
L1.Oberösterreich 0.145845 0.054410 2.680 0.007
L1.Salzburg 0.039122 0.026497 1.476 0.140
L1.Steiermark 0.017150 0.035104 0.489 0.625
L1.Tirol 0.077037 0.027857 2.765 0.006
L1.Vorarlberg 0.057527 0.024964 2.304 0.021
L1.Wien 0.084739 0.048635 1.742 0.081
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199894 0.049027 4.077 0.000
L1.Burgenland 0.043539 0.025274 1.723 0.085
L1.Kärnten -0.005139 0.012143 -0.423 0.672
L1.Niederösterreich 0.126717 0.053802 2.355 0.019
L1.Oberösterreich 0.300871 0.053160 5.660 0.000
L1.Salzburg 0.099274 0.025889 3.835 0.000
L1.Steiermark 0.142784 0.034298 4.163 0.000
L1.Tirol 0.075532 0.027218 2.775 0.006
L1.Vorarlberg 0.057033 0.024391 2.338 0.019
L1.Wien -0.042124 0.047518 -0.886 0.375
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205753 0.098391 2.091 0.037
L1.Burgenland -0.057521 0.050722 -1.134 0.257
L1.Kärnten -0.038012 0.024370 -1.560 0.119
L1.Niederösterreich 0.066565 0.107973 0.616 0.538
L1.Oberösterreich 0.190837 0.106685 1.789 0.074
L1.Salzburg 0.266681 0.051955 5.133 0.000
L1.Steiermark 0.085408 0.068831 1.241 0.215
L1.Tirol 0.128531 0.054622 2.353 0.019
L1.Vorarlberg 0.121349 0.048949 2.479 0.013
L1.Wien 0.034356 0.095361 0.360 0.719
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.033739 0.077306 0.436 0.663
L1.Burgenland 0.024713 0.039853 0.620 0.535
L1.Kärnten 0.052688 0.019148 2.752 0.006
L1.Niederösterreich 0.195165 0.084835 2.301 0.021
L1.Oberösterreich 0.345338 0.083823 4.120 0.000
L1.Salzburg 0.048785 0.040821 1.195 0.232
L1.Steiermark -0.002348 0.054081 -0.043 0.965
L1.Tirol 0.114106 0.042917 2.659 0.008
L1.Vorarlberg 0.065088 0.038460 1.692 0.091
L1.Wien 0.124047 0.074926 1.656 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165590 0.093434 1.772 0.076
L1.Burgenland 0.031041 0.048167 0.644 0.519
L1.Kärnten -0.054437 0.023142 -2.352 0.019
L1.Niederösterreich -0.107494 0.102533 -1.048 0.294
L1.Oberösterreich 0.188582 0.101310 1.861 0.063
L1.Salzburg 0.029380 0.049337 0.595 0.552
L1.Steiermark 0.297586 0.065363 4.553 0.000
L1.Tirol 0.488545 0.051870 9.419 0.000
L1.Vorarlberg 0.076701 0.046483 1.650 0.099
L1.Wien -0.112226 0.090557 -1.239 0.215
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156982 0.102543 1.531 0.126
L1.Burgenland -0.006027 0.052862 -0.114 0.909
L1.Kärnten 0.064504 0.025398 2.540 0.011
L1.Niederösterreich 0.201463 0.112529 1.790 0.073
L1.Oberösterreich -0.130813 0.111187 -1.177 0.239
L1.Salzburg 0.246716 0.054147 4.556 0.000
L1.Steiermark 0.158886 0.071736 2.215 0.027
L1.Tirol 0.046803 0.056927 0.822 0.411
L1.Vorarlberg 0.123981 0.051015 2.430 0.015
L1.Wien 0.140514 0.099385 1.414 0.157
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.524021 0.055207 9.492 0.000
L1.Burgenland -0.023064 0.028460 -0.810 0.418
L1.Kärnten -0.009647 0.013674 -0.705 0.481
L1.Niederösterreich 0.188183 0.060584 3.106 0.002
L1.Oberösterreich 0.249211 0.059861 4.163 0.000
L1.Salzburg 0.021343 0.029152 0.732 0.464
L1.Steiermark -0.023939 0.038621 -0.620 0.535
L1.Tirol 0.075281 0.030648 2.456 0.014
L1.Vorarlberg 0.060956 0.027465 2.219 0.026
L1.Wien -0.060663 0.053507 -1.134 0.257
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021407 0.065820 0.128377 0.110547 0.028116 0.061800 -0.003438 0.169810
Kärnten 0.021407 1.000000 -0.060368 0.131494 0.044032 0.051250 0.446050 -0.093335 0.101821
Niederösterreich 0.065820 -0.060368 1.000000 0.285491 0.091004 0.277676 0.014913 0.143562 0.253688
Oberösterreich 0.128377 0.131494 0.285491 1.000000 0.173170 0.295710 0.165533 0.117961 0.126287
Salzburg 0.110547 0.044032 0.091004 0.173170 1.000000 0.126944 0.042477 0.105076 0.049200
Steiermark 0.028116 0.051250 0.277676 0.295710 0.126944 1.000000 0.120652 0.088929 -0.026815
Tirol 0.061800 0.446050 0.014913 0.165533 0.042477 0.120652 1.000000 0.037619 0.127560
Vorarlberg -0.003438 -0.093335 0.143562 0.117961 0.105076 0.088929 0.037619 1.000000 -0.048327
Wien 0.169810 0.101821 0.253688 0.126287 0.049200 -0.026815 0.127560 -0.048327 1.000000